package com.atao.baokede.utils;

/**
 * ThreadLocal 工具类
 */
@SuppressWarnings("all")
public class ThreadLocalUtil {
    //提供ThreadLocal对象,
    private static final ThreadLocal THREAD_LOCAL = new ThreadLocal();

    // 提供ThreadLocal对象,用于存储商户信息
    private static final ThreadLocal MERCHANT_THREAD_LOCAL = new ThreadLocal();

    //根据键获取用户值
    public static <T> T get(){
        return (T) THREAD_LOCAL.get();
    }

    //存储用户键值对
    public static void set(Object value){
        THREAD_LOCAL.set(value);
    }

    // 根据键获取商户值
    public static <T> T getMerchant(){
        return (T) MERCHANT_THREAD_LOCAL.get();
    }

    // 存储商户键值对
    public static void setMerchant(Object value){
        MERCHANT_THREAD_LOCAL.set(value);
    }

    //清除ThreadLocal 防止内存泄漏
    public static void remove(){
        THREAD_LOCAL.remove();
        MERCHANT_THREAD_LOCAL.remove();
    }
}